package com.example.statemachine.event;

import com.example.statemachine.StatesEvents;
import com.example.statemachine.action.StartToNewAction;
import com.example.statemachine.guard.StartToNewGuard;
import lombok.AllArgsConstructor;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.stereotype.Component;

/**
 * @Author: leizj
 * @Desc:
 */
@Component
@AllArgsConstructor
public class InitiateEvent implements StateMachineEvent {
    private StartToNewGuard startToNewGuard;
    private StartToNewAction startToNewAction;

    @Override
    public void configure(StateMachineTransitionConfigurer<StatesEvents.State, StatesEvents.Event> transitions) throws Exception {
        transitions
                .withExternal()
                .source(StatesEvents.State.START)
                .event(StatesEvents.Event.INITIATE)
                .target(StatesEvents.State.NEW)
                .action(startToNewAction);
    }
}
